/*******************************************************************************
 * Copyright (c) 2013 Michele Nanna.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the GNU Public License v3.0
 * which accompanies this distribution, and is available at
 * http://www.gnu.org/licenses/gpl.html
 * 
 * Contributors:
 *     Michele Nanna - initial API and implementation
 ******************************************************************************/
package com.systemfastforward.provinciawifi.ui.adapter;

import java.util.List;

import nl.matshofman.saxrssreader.RssItem;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.systemfastforward.provinciawifi.R;

public class SocialFeedAdapter extends BaseAdapter {
	private List<RssItem> mItems;

	public SocialFeedAdapter(List<RssItem> items) {
		mItems = items;
	}
	
	@Override
	public int getCount() {
		return mItems.size();
	}

	@Override
	public Object getItem(int position) {
		return mItems.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		Context ctx = parent.getContext();
		RelativeLayout root = (RelativeLayout) convertView;

		if (convertView == null) {
			LayoutInflater inflater = (LayoutInflater) ctx.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
			root = (RelativeLayout) inflater.inflate(R.layout.social_listview_item, null);
		}
		
		TextView text = (TextView) root.findViewById(R.id.social_item_text);
		text.setText(mItems.get(position).getDescription());
		
		return root;
	}
}
